package rsj.api.org.importdata;

import com.rlyy.aibase.utils.base.Box;
import common.util.BoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.org.importdata.entity.ImportFailedParam;
import rsj.api.user.BaseLink;
import rsj.service.QueryImportFailureData;
import common.util.validator.ParameterConversionCheck;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * 查询导入失败的数据
 *
 * @author yuanqinglong
 * @since 2021/3/9 16:31
 */
@RestController
public class QueryImportFailureDataController extends BaseLink {

    @Autowired
    private QueryImportFailureData queryImportFailureData;

    /**
     * 查询导入失败的数据
     *
     * @param box 参数
     * @return 失败的数据列表
     */
    @Override
    @RequestMapping(value = "rsj_query_import_failed_data")
    public Box executeLink(Box box) {
        ImportFailedParam importFailedParam = (ImportFailedParam) ParameterConversionCheck.parameterConversionCheckFastFail(box, ImportFailedParam.class);
        if (importFailedParam.getImportTimestamp() != null) {
            LocalDateTime importDateTime = Instant.ofEpochMilli(importFailedParam.getImportTimestamp()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
            importFailedParam.setImportTime(importDateTime);
        }
        return BoxUtil.successBox(box).putMapNode("data", queryImportFailureData.detailsOfFailedData(importFailedParam));
    }


}
